﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using SmsMeta.StructureRequest;

namespace SmsMeta
{
    public class DirectRequest
    {
        private RessourceQuery REST; 
        public DirectRequest(RessourceQuery rq)
        {
            REST = rq;
        }

        public XmlDocument GetObjectOfQuery()
        {
            XmlDocument xDoc = null;

            if (REST.Domain == RessourceDomain.StructuralMetadata)
            {
                QueryHelper qh = new QueryHelper(REST.ArTyped, REST.Query);
                BaseArtefactRequest artefactRequest = null;

                switch (REST.ArTyped.Type)
                {
                    case SdmxMl.Manager.SdmxArtefactType.HierarchicalCodelists:
                        artefactRequest = new HierarchicalCodelistRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.Concepts:
                        artefactRequest = new ConceptSchemeRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.CodeLists:
                        artefactRequest = new CodelistRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.OrganisationSchemes:
                        artefactRequest = new OrgSchemeRequest(qh);
                        break;


                    case SdmxMl.Manager.SdmxArtefactType.Dataflows:
                        artefactRequest = new DataFlowRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.Metadataflows:
                        artefactRequest = new MetaDataFlowRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.KeyFamilies:
                        artefactRequest = new DataStructureRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.MetadataStructureDefinitions:
                        artefactRequest = new MetaDataStructureRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.CategorySchemes:
                        artefactRequest = new CategorySchemeRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.Processes:
                        artefactRequest = new ProcessRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.StructureSets:
                        artefactRequest = new StructureSetRequest(qh);
                        break;
                    case SdmxMl.Manager.SdmxArtefactType.MetadataSet:
                        artefactRequest = new MetadataSetRequest(qh);
                        break;

                }

                if (artefactRequest != null)
                    xDoc = artefactRequest.GetSdmxMl();
                else
                    REST.StatusCode = (int)HttpStatus.NotImplemented;
            }
            else
                REST.StatusCode = (int)HttpStatus.NotImplemented;


            return xDoc;
        }
    }
}
